package com.duqc.designpattern.observer;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName PayServiceImpl
 * @Description TODO
 * @Author duqc
 * @Date 2021/5/11
 **/
@Slf4j
@RestController
public class PayServiceImpl {

    @Resource
    private ApplicationContext ctx;

    @GetMapping("demo")
    public String pay() {

        Map<String, String> map = new HashMap<>();
        map.put("msg", "msg");
        //创建一个支付事件
        PayEvent payEvent = new PayEvent(this, map, "支付");
        //获取Spring的ApplicationContext容器，发布事件，监听类监听到事件后就会发送消息
        ctx.publishEvent(payEvent);
        log.info("消息处理后的逻辑代码");
        return "msg";
    }
}
